/**
 * @Author: lusx
 * @Date:   29-03-2019 04:14:46
 * @Project: Govern督办
 * @Last modified by:   lusx
 * @Last modified time: 01-04-2019 03:45:07
 */
 import React, { Component } from 'react';
 import { Avatar,WhiteSpace,WingBlank,Icon,Flex,Button} from 'weaver-mobile';
 import { withRouter } from 'react-router-dom';
 import { Tools} from 'weaver-mobile';
 import { Base64 } from 'js-base64';
 import { asyncComponent } from 'react-async-component';
 const getLabel = Tools.getLabel;
 const coms = {
   EditPage: asyncComponent({
     resolve: () => import("../../info/pages/addPages/editPage.js")
   }),
 };
 //渲染每条回复
 @withRouter
 class ComReplyItem extends Component {
    constructor(props) {
      super(props);
      this.state={
        isaction : false
      }
    }
   render(){
     const {replyData:{content,createdate,createtime,userName,imageurl,id ,instruUserName=""},match:{path}} = this.props;
     return (
       <div className="g-comReplyItem" >
       <WhiteSpace size="md" />
       <WingBlank size="md">
       <div className="g-comReplyItem-title"><Avatar name="userName" url="imageurl" />
       <span className="g-comReplyItem-user">{userName}
       <span className='g-comReplyItem-text'>{instruUserName.split('').length>0?getLabel('555','回复'):''}</span>
       {instruUserName}
       </span>
       </div>
       <div className="g-comReplyItem-container">
       <div className="ql-editor"
       dangerouslySetInnerHTML={{
         __html: `${Base64.decode(content)}`
       }}
       />
       <Flex align="start" justify="between" className="g-opinion-flex">
          <div className="g-comReplyItem-time">{createdate}&nbsp;{createtime}</div>
          <div className={this.state.isaction ? 'g-opinion-comment g-opinion-comment-isaction' :'g-opinion-comment'}><Icon type="reply" size='xxs' color='#888' onClick={this.clickHandle.bind(this,id)}/><span className='g-comment-number'></span></div>
       </Flex>
       </div>
       </WingBlank>
         </div>
       );
   }
   clickHandle(id,e){
     if(e) {e.preventDefault(); e.stopPropagation();}
     this.setState({isaction: true})
     let timeoutflag = null;
     const {match:{url},history:{push},editType,taskId,instructTopid} = this.props;
     const path = url.substr(0,url.indexOf('/opinionChild'));
     if(timeoutflag != null){
      clearTimeout(timeoutflag);
      timeoutflag = null;
    }else{
      timeoutflag=setTimeout(function(){
        push(`${path}/edit/${editType}?id=${taskId}&instructTopid=${instructTopid}&instructid=${id}`);
      },500);
    }
   }
 }
 export default ComReplyItem;
